﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Echinus
{
    class DbParams
    {
        public DbParams()
        {
         
        }

        public static System.Data.Common.DbConnection GetConnection()
        {
            System.Data.Common.DbConnection dbconn = null;

                switch (dbtype)
                {
                    case DbServerType.SQLServer:
                        dbconn = new System.Data.SqlClient.SqlConnection();
                        break;
                    case DbServerType.Access:
                        dbconn = new System.Data.OleDb.OleDbConnection();
                        break;
                    default:
                        break;
                }

                try
                {
                    dbconn.ConnectionString = strConnection;
                }
            catch
                {

            }
            return dbconn;
        }

        public static System.Data.Common.DbCommand GetDbCommand()
        {
            System.Data.Common.DbCommand commd = null;

            switch (dbtype)
            {
                case DbServerType.SQLServer:
                    commd = new System.Data.SqlClient.SqlCommand();
                    break;
                case DbServerType.Access:
                    commd = new System.Data.OleDb.OleDbCommand();
                    break;
                default:
                    break;
            }

            return commd;
        }

        public static System.Data.Common.DbDataAdapter GetDataAdapter()
        {
            System.Data.Common.DbDataAdapter dataAdapter = null;

            switch (dbtype)
            {
                case DbServerType.SQLServer:
                    dataAdapter = new System.Data.SqlClient.SqlDataAdapter();
                    break;
                case DbServerType.Access:
                    dataAdapter = new System.Data.OleDb.OleDbDataAdapter();
                    break;
                default:
                    break;
            }

            return dataAdapter;
        }

        //public static System.Data.Common.DbDataAdapter GetDataReader()
        //{
        //    System.Data.Common.DbDataReader dr = null;

        //    switch (dbtype)
        //    {
        //        case DbServerType.SQLServer:
        //            dr = new System.Data.SqlClient.SqlDataReader();
        //            break;
        //        case DbServerType.Access:
        //            dr = new System.Data.OleDb.OleDbDataReader();
        //            break;
        //        default:
        //            break;
        //    }

        //    return dr;
        //}

        public static DbServerType dbtype = DbServerType.None;   //默认没有初始化
        public static string strConnection = "";    //默认没有初始化
    }

    enum DbServerType
    {
        SQLServer, Access, Sqlite,None
    }

}
